package com.daniel.mi.service.Impl;

import com.daniel.mi.service.OrderService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author zengneng46764
 * @Date 2024/3/20 22:45
 * @description: TODO
 */
@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void makeFonoutOrder() {
        String message = "123";
        String exchangeName = "fanout.order.exchange";
        String routeingKey = "";
        rabbitTemplate.convertAndSend(exchangeName, routeingKey, message);
        System.out.println("订单生成成功：" + message);
    }

    @Override
    public void makeDirectOrder() {
        //交换机名称
        String exchangeName ="itcast.direct";
        //消息
        String message = "hello, yellow!";
        // 队列
        String routingKey = "yellow";
        // 发送消息，参数分别是：交互机名称、RoutingKey(指定队列key)、消息
        rabbitTemplate.convertAndSend(exchangeName, routingKey, message);
        System.out.println("订单生成成功：" + message);
    }

    @Override
    public void makeTopicOrder() {
//交换机名称
        String exchangeName ="itcast.topic";
        String message = "今天是个好日子!";
        rabbitTemplate.convertAndSend(exchangeName,"USA.news",message);
        System.out.println("订单生成成功：" + message);
    }
}
